package com.mf.service;

import java.sql.Connection;
import java.util.List;

import com.mf.dao.UserDao;
import com.mf.daoImpl.PictureDaoImpl;
import com.mf.daoImpl.UserDaoImpl;
import com.mf.entity.Picture;
import com.mf.entity.User;
import com.mf.util.DButil;

public class UserService {
	
	UserDaoImpl userDaoImpl=new UserDaoImpl();
	
	public void add(User user){
		userDaoImpl.add(user);
	}
	
	public void delete(User user){
		userDaoImpl.delete(user);
	}
	
	public void update(User user){
		userDaoImpl.update(user);
	}
	
	public User select(User user){
		return userDaoImpl.select(user);
	}
	
	public User selectUserbyEmail(String email){
		return userDaoImpl.selectUserbyEmail(email);
	}
	
	public List<User> selectAll(){
		return userDaoImpl.selectAll();
	}
	
	/**
	 * 
	 * if return true agree login
	 * else password wrong
	 * @param email
	 * @param password
	 * @return
	 */
	public boolean loginReturnBool(String email,String password){
		
		User findUser=userDaoImpl.selectUserbyEmail(email);
		if (null==findUser||findUser.getEmail().isEmpty()) {
			return false;
		}else if(findUser.getPwd().equals(password)){
			return true;
		}else{
			return false;
		}
		
	}
	
	
	
	/**
	 * @param email
	 * @param password
	 * @return
	 */
	public User loginReturnUser(String email,String password){
		
		User findUser=userDaoImpl.selectUserbyEmail(email);
		if (null==findUser||findUser.getEmail().isEmpty()) {
			return null;
		}else if(findUser.getPwd().equals(password)){
			return findUser;
		}else{
			return null;
		}
		
	}
	
	

}
